<?php
include_once 'common/common.function.php';
include_once 'common/database.class.php';
?>

<?php 
if(!empty($_POST['submit'])){
		
	$ServerTypeId = intval($_POST['server_type']);
	$ServerName = addslashes($_POST['server_name']);
	$ServerDesc = addslashes($_POST['server_desc']);
	$ServerHost = addslashes($_POST['server_host']);
	$CreateTime = time();
	
	
	if($ServerTypeId=='' || $ServerName == '' || $ServerDesc == '' || $ServerDesc == '' ){
		echo '内容不能为空';
		header('location:server_add.php');
		exit;
	}
	
	/** 测试是否能请求通过 **/
	include_once 'common/httpdown.class.php';
	$httpdown = new httpdown();
	$httpdown->connect($ServerHost);	
	if($httpdown->connect_status()!='200'){
		echo '地址：'.$ServerHost.'连接不通。';
		header('location:server_add.php');
		exit;
	}	
	/** 测试是否能请求通过 **/
	
	$sql = "
		insert into yabb_sys_server_list values (NULL,'{$ServerTypeId}','{$ServerName}','{$ServerDesc}','{$ServerHost}','{$CreateTime}','0','0')
	";
	
	$db = new DataBase();
	$db->execute($sql);
	
	echo '添加成功<br>';
	echo '<a href="form.php">返回</a>';

}else{
	$db = new DataBase();
	$sql = " select * from yabb_sys_server_type ";
	$sever_type = $db->get_all($sql);
?>
<form method="post">
<table>
<tr>
<td align="right">服务器名称：</td>
<td><input type="text" name="server_name" /></td>
</tr>

<tr>
<td align="right">服务器 host：</td>
<td><input type="text" name="server_host"  value="" /></td>
</tr>

<tr>
<td align="right">服务器描述：</td>
<td><textarea name="server_desc"></textarea></td>
</tr>

<tr>
<td align="right">服务器分组：</td>
<td>
<select name="server_type">
<?php foreach($sever_type as $val){ ?>
<option value="<?php echo $val['Id'];?>"><?php echo $val['TypeName'];?></option>
<?php }?>
</select>
</td>
</tr>

<tr>
<td align="right"></td>
<td>
<input type="submit"  name="submit" value="新增"/>
<input type="reset"  name="reset" value="取消"/>
</td>
</tr>

</table>
</form>
<?php }?>
